<template>
  <div class="page-header-index-wide">
    <a-row :gutter="24">
      <a-col :sm="24" :md="16" :xl="8" :style="{ marginBottom: '24px' }">
        <chart-card :loading="loading" title="总用户量" :total="loginfo.totalUserNum">
          <!-- <div> -->
<!--            <trend style="margin-right: 16px;" flag="">
              <span slot="term">今日活跃</span>
              {{loginfo.todayIp}}
            </trend>
            <trend flag="up">
              <span slot="term">今日新增</span>
              {{loginfo.todayAddNum}}
            </trend> -->
          <!-- </div> -->
          <!-- <template slot="footer">日均增长率<span>{{loginfo.dailyUp}} %</span></template> -->
        </chart-card>
      </a-col>

      <a-col :sm="24" :md="16" :xl="8" :style="{ marginBottom: '24px' }">
        <chart-card :loading="loading" title="今日活跃" :total="loginfo.todayActiveMember | NumberFormat">
        </chart-card>
      </a-col>
      
      <a-col :sm="24" :md="16" :xl="8" :style="{ marginBottom: '24px' }">
        <chart-card :loading="loading" title="今日新增" :total="loginfo.todayAddNum | NumberFormat">
        </chart-card>
      </a-col>
      
      <a-col :sm="24" :md="16" :xl="8" :style="{ marginBottom: '24px' }">
        <chart-card :loading="loading" title="日均增长率" :total="loginfo.dailyUp + '%'">
        </chart-card>
      </a-col>
      
      <a-col :sm="24" :md="16" :xl="8" :style="{ marginBottom: '24px' }">
        <chart-card :loading="loading" title="日均活跃率" :total="loginfo.avgActivityRate + '%'">
        </chart-card>
      </a-col>
      
      
<!--      <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px' }">
        <chart-card :loading="loading" title="支付笔数" :total="6560 | NumberFormat">
          <a-tooltip title="指标说明" slot="action">
            <a-icon type="info-circle-o" />
          </a-tooltip>
          <div>
            <mini-bar :height="40" />
          </div>
          <template slot="footer">转化率 <span>60%</span></template>
        </chart-card>
      </a-col> -->
      
<!--      <a-col :sm="24" :md="12" :xl="6" :style="{ marginBottom: '24px' }">
        <chart-card :loading="loading" title="运营活动效果" total="78%">
          <a-tooltip title="指标说明" slot="action">
            <a-icon type="info-circle-o" />
          </a-tooltip>
          <div>
            <mini-progress color="rgb(19, 194, 194)" :target="80" :percentage="78" :height="8" />
          </div> 
          <template slot="footer">
            <trend flag="down" style="margin-right: 16px;">
              <span slot="term">同周比</span>
              12%
            </trend>
            <trend flag="up">
              <span slot="term">日环比</span>
              80%
            </trend>
          </template>
        </chart-card>
      </a-col> -->
    </a-row>

<!--    <a-card :loading="loading" :bordered="false" :body-style="{padding: '0'}">
      <div class="salesCard">
        <a-tabs default-active-key="1" size="large" :tab-bar-style="{marginBottom: '24px', paddingLeft: '16px'}">
          <div class="extra-wrapper" slot="tabBarExtraContent">
            <div class="extra-item">
              <a @click="getDayActiveTotal('1')">三日内</a>
              <a @click="getDayActiveTotal('2')">本周内</a>
              <a @click="getDayActiveTotal('3')">本月内</a>
            </div>
          </div>
          <a-tab-pane loading="true" tab="用户活跃量" key="1">
            <a-row>
              <a-col>
                <bar :dataSource="activeBarData" />
                <div v-if="activeBarData.length == 0">
                  <a-empty />
                </div>
              </a-col>
            </a-row>
          </a-tab-pane>
        </a-tabs>
      </div>
    </a-card> -->


   <a-card :loading="loading" :bordered="false" :body-style="{padding: '0'}">
      <div class="salesCard">
        <a-tabs default-active-key="1" size="large" :tab-bar-style="{marginBottom: '24px', paddingLeft: '16px'}">
          <div class="extra-wrapper" slot="tabBarExtraContent">
            <div class="extra-item">
              <a @click="getDayActiveTotal('1')">三日内</a>
              <a @click="getDayActiveTotal('2')">本周内</a>
              <a @click="getDayActiveTotal('3')">本月内</a>
            </div>
          </div>
          <a-tab-pane loading="true" tab="用户活跃量" key="1">
            <a-row>
              <a-col>
                <bar :dataSource="activeBarData" />
                <div v-if="activeBarData.length == 0">
                  <a-empty />
                </div>
              </a-col>
            </a-row>
          </a-tab-pane>
        </a-tabs>
      </div>
    </a-card>

    <br />

   <a-card :loading="loading" :bordered="false" :body-style="{padding: '0'}">
      <div class="salesCard">
        <a-tabs default-active-key="1" size="large" :tab-bar-style="{marginBottom: '24px', paddingLeft: '16px'}">
          <div class="extra-wrapper" slot="tabBarExtraContent">
            <div class="extra-item">
              <a @click="getDayAddtTotal('1')">三日内</a>
              <a @click="getDayAddtTotal('2')">本周内</a>
              <a @click="getDayAddtTotal('3')">本月内</a>
            </div>
          </div>
          <a-tab-pane loading="true" tab="用户增长量" key="1">
            <a-row>
              <a-col>
                <bar :dataSource="barDataTest" />
                <div v-if="barDataTest.length == 0">
                  <a-empty />
                </div>
              </a-col>
            </a-row>
          </a-tab-pane>
        </a-tabs>
      </div>
    </a-card>




    <a-row>
      <a-col :span="24">
        <a-card :loading="loading" :bordered="false" title="最近一周访问量统计" :style="{ marginTop: '24px' }">
          <a-row>
            <a-col :span="6">
              <head-info title="今日活跃" :content="loginfo.todayIp"></head-info>
            </a-col>
            <a-col :span="2">
              <a-spin class='circle-cust'>
                <a-icon slot="indicator" type="environment" style="font-size: 24px" />
              </a-spin>
            </a-col>
            <a-col :span="6">
              <head-info title="今日访问" :content="loginfo.todayVisitCount"></head-info>
            </a-col>
            <a-col :span="2">
              <a-spin class='circle-cust'>
                <a-icon slot="indicator" type="team" style="font-size: 24px" />
              </a-spin>
            </a-col>
            <a-col :span="6">
              <head-info title="总访问量" :content="loginfo.totalVisitCount"></head-info>
            </a-col>
            <a-col :span="2">
              <a-spin class='circle-cust'>
                <a-icon slot="indicator" type="rise" style="font-size: 24px" />
              </a-spin>
            </a-col>
          </a-row>
          <!-- <line-chart-multid :fields="visitFields" :dataSource="visitInfo"></line-chart-multid> -->
          <line-chart-multid :fields="visitFields" :dataSource="visitInfo"></line-chart-multid>
        </a-card>
      </a-col>
    </a-row>


  </div>
</template>

<script>
  import ChartCard from '@/components/ChartCard'
  import ACol from "ant-design-vue/es/grid/Col"
  import ATooltip from "ant-design-vue/es/tooltip/Tooltip"
  import MiniArea from '@/components/chart/MiniArea'
  import MiniBar from '@/components/chart/MiniBar'
  import MiniProgress from '@/components/chart/MiniProgress'
  import RankList from '@/components/chart/RankList'
  import Bar from '@/components/chart/Bar'
  import LineChartMultid from '@/components/chart/LineChartMultid'
  import HeadInfo from '@/components/tools/HeadInfo.vue'

  import Trend from '@/components/Trend'
  import {
    getLoginfo,
    getVisitInfo
  } from '@/api/api'

  const rankList = []
  for (let i = 0; i < 7; i++) {
    rankList.push({
      name: '白鹭岛 ' + (i + 1) + ' 号店',
      total: 1234.56 - i * 100
    })
  }
  const barData = []

  const barDataTest = []
  
  const activeBarData = []
  // for (let i = 0; i < 12; i += 1) {
  //   barData.push({
  //     x: `${i + 1}月`,
  //     y: Math.floor(Math.random() * 1000) + 200
  //   })
  // }

  export default {
    name: "IndexChart",
    components: {
      ATooltip,
      ACol,
      ChartCard,
      MiniArea,
      MiniBar,
      MiniProgress,
      RankList,
      Bar,
      Trend,
      LineChartMultid,
      HeadInfo
    },
    data() {
      return {
        searchType: '1',
        activeSearchType: '1',
        loading: true,
        center: null,
        rankList,
        barData,
        barDataTest,
        activeBarData,
        loginfo: {},
        visitFields: ['ip', 'visit'],
        visitInfo: [],
        indicator: <a- icon type = "loading" style = "font-size: 24px" spin / >
      }
    },
    created() {
      setTimeout(() => {
        this.loading = !this.loading
      }, 1000)
      this.initLogInfo();
      //三日内用户增长量
      this.getDayAddtTotal();
      //三日内用户活跃量
      this.getDayActiveTotal();

    },
    methods: {
      initLogInfo() {
        getLoginfo(null).then((res) => {
          if (res.success) {
            Object.keys(res.result).forEach(key => {
              res.result[key] = res.result[key] + ""
            })
            this.loginfo = res.result;
          }
        })
        getVisitInfo().then(res => {
          if (res.success) {
            this.visitInfo = res.result;
          }
        })
      },
      getDayAddtTotal(days) {//获取每日增长的用户数量
        if (days) {
          this.searchType = days;
        }
        this.barDataTest = [];
        this.axios.get("/sys/addTotalMember", {
          params: {
            searchType: this.searchType
          }
        }).then((res) => {
          var array = [];
          array = res.result;
          for (let i = 0; i < array.length; i++) {
            this.barDataTest.push({
              x: `${array[i].day}日`,
              y: parseInt(array[i].member)
            })
          }
          console.log(this.barDataTest);
        });
      },
      
      getDayActiveTotal(days){//获取每天的活跃用户数量
        if(days){
           this.activeSearchType = days;
        }
        this.activeBarData = [];
        this.axios.get("/sys/activeTotalMember", {
          params: {
            searchType: this.activeSearchType
          }
        }).then((res) => {
          var array2 = [];
          array2 = res.result;
          for (let i = 0; i < array2.length; i++) {
            this.activeBarData.push({
              x: `${array2[i].day}日`,
              y: parseInt(array2[i].member)
            })
          }
          console.log(this.activeBarData);
        });
      }
    }
  }
</script>

<style lang="less" scoped>
  .circle-cust {
    position: relative;
    top: 28px;
    left: -100%;
  }

  .extra-wrapper {
    line-height: 55px;
    padding-right: 24px;

    .extra-item {
      display: inline-block;
      margin-right: 24px;

      a {
        margin-left: 24px;
      }
    }
  }
  
  .extra-wrapper1 {
    line-height: 55px;
    padding-right: 24px;
  
    .extra-item1 {
      display: inline-block;
      margin-right: 24px;
  
      a {
        margin-left: 24px;
      }
    }
  }

  /* 首页访问量统计 */
  .head-info {
    position: relative;
    text-align: left;
    padding: 0 32px 0 0;
    min-width: 125px;

    &.center {
      text-align: center;
      padding: 0 32px;
    }

    span {
      color: rgba(0, 0, 0, .45);
      display: inline-block;
      font-size: .95rem;
      line-height: 42px;
      margin-bottom: 4px;
    }

    p {
      line-height: 42px;
      margin: 0;

      a {
        font-weight: 600;
        font-size: 1rem;
      }
    }
  }
</style>
